package com.kmproject.haifu.mvp.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.TimeUtils;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowInfoBean;
import com.kmproject.haifu.mvp.presenter.MyStoreLookObtainedPresenter;
import com.kmproject.haifu.mvp.ui.activity.HouseRentShowInfoActivity;

import java.util.ArrayList;
import java.util.List;

public class ObtainedHouseItemAdapter extends BaseQuickAdapter<HouseRentListShowInfoBean, BaseViewHolder> {
    ImageLoader glideImage;
    String mTime;
//    MyStoreLookObtainedPresenter mmyStoreLookObtainedPresenter;
    public ObtainedHouseItemAdapter(String time,@Nullable List<HouseRentListShowInfoBean> data) {
        super(R.layout.mystore_story_middle_item, data);
        mTime=time;
//        this.mmyStoreLookObtainedPresenter=myStoreLookObtainedPresenter;
    }

    @Override
    protected void convert(BaseViewHolder helper, HouseRentListShowInfoBean item) {
        if (glideImage == null) {
            glideImage = ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
       if (item.getHouseImageList()!=null&&!item.getHouseImageList().isEmpty())
       {
           glideImage.loadImage(mContext, ImageConfigImpl.builder().url(item.getHouseImageList().get(0).getImageUrl())
                   .imageView(helper.<ImageView>getView(R.id.mystore_story_middle_item_img))
                   .build());
       }
       if (Integer.parseInt(mTime) < Integer.parseInt(TimeUtils.getYear().length()>4?TimeUtils.getYear().substring(0,4):TimeUtils.getYear()))
       {
         helper.<LinearLayout>getView(R.id.mystore_story_middle_item_del_lay).setVisibility(View.VISIBLE);
       }else {
           helper.<LinearLayout>getView(R.id.mystore_story_middle_item_del_lay).setVisibility(View.INVISIBLE);
       }
        if ("dz".equals(item.getRentType()))
        {
            helper.setText(R.id.mystore_story_middle_item_unit,"/天");
        }else {
            helper.setText(R.id.mystore_story_middle_item_unit,"/月");
        }

        helper.<TextView>getView(R.id.mystore_story_middle_item_money).setText(item.getFormatMonthRent()+"P");
        helper.<TextView>getView(R.id.mystore_story_middle_item_time_txt).setText(item.getLowerShelfTime().substring(0,16)+" 下架");
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, HouseRentShowInfoActivity.class);
                intent.putExtra("rentId",item.getRentId());
                intent.putExtra("lgt","0");
                intent.putExtra("lat","0");
                intent.putExtra("type","userCenterInfo");
                ArmsUtils.startActivity(intent);
            }
        });
        helper.addOnClickListener(R.id.mystore_story_middle_item_del_lay);
//        helper.<LinearLayout>getView(R.id.mystore_story_middle_item_del_lay).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
////                mmyStoreLookObtainedPresenter.removeStore(item.getRentId());
//            }
//        });
        if ("jmzz".equals(item.getHouseCategory()))
        {
            //居民
            if ("hz".equals(item.getRentType()))
            {
                helper.setText(R.id.mystore_story_middle_item_titile,item.getRentTypeName()+"."+item.getRoomCountName()+item.getToiletCountName()+item.getDrawingCountName()+"."+item.getRentRoomName()+"."+item.getHouseName());

            }else {
                helper.setText(R.id.mystore_story_middle_item_titile,item.getRentTypeName()+"."+item.getRoomCountName()+item.getToiletCountName()+item.getDrawingCountName()+"."+item.getHouseName());

            }
            return;
        }else {
            //商业用地
            helper.<TextView>getView(R.id.mystore_story_middle_item_titile).setText(item.getHouseName());
        }



    }

}
